
<% include("../common/head.html"){} %>

<div class="easyui-panel" data-options="fit:true,boarder:false">
	<table class="easyui-datagrid" id="dataGrid" data-options="url:'/dict/query',
		rownumbers:true,pagination:true,pageNumber:1,pageSize:20,pagePosition:'bottom',
		fit:true,toolbar:'#search',singleSelect:true,showFooter:true">
		<thead>
			<tr>
				<th data-options="field:'id',width:100">Id</th>
				<th data-options="field:'name',width:100">字典名称</th>
				<th data-options="field:'value'">字典描述</th>
				<th data-options="field:'order'">字典顺序</th>
			</tr>
		</thead>
	</table>
	
	<div id="search" class="tableSearch">
		<input id="search_parent_id" class="easyui-combobox" name="parent_id"   
    		data-options="valueField:'id',textField:'name',url:'/dict/parentDict',
    		onSelect: function(rec){
            $('#dataGrid').datagrid('load',{
				name: $('#name').val(),
				parent_id: rec.id
				});
            }"  />  
		<input type="text" id="name" size=10  placeholder="字典名称" />
    	<button class="btn btn-default" id="btnSearch">查 询</button>
    	<button class="btn btn-default" onclick="resetForm();">重 置</button>
    	<br/>
    	<input id="comboboxTest"  class="easyui-combobox" data-options="valueField:'name',textField:'value',url:'/dict/getDicts?name=学历'"  /> 
    	<button class="btn btn-default" id="btnTest">测试</button> 
    	<br/>
	<% if(so.hasRole("admin")){%>
		<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="add()">新增字典</a> 
	<%}%>
	<% if(so.hasRole("admin")){%>
		<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="edit()">修改字典</a> 
	<%}%>
	<% if(so.hasRole("admin")){%>
		<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="remove()">删除字典</a>
	<%}%> 
	</div>
</div>


<div id="dlg" class="easyui-dialog" style="width:400px;height:200px;padding:10px 20px"
	closed="true" buttons="#dlg-buttons">
	<form id="fm" method="post" novalidate>
        	<div class="fitem">
                <label>从属:</label>
                <input id="parent_id" class="easyui-combobox" name="parent_id"   
    				data-options="valueField:'id',textField:'name',url:'/dict/parentDict'" >
            </div>
            <div class="fitem">
                <label>名称:</label>
                <input name="name" class="easyui-textbox" required="true" >
            </div>
            <div class="fitem">
                <label>字典:</label>
                <input name="value" class="easyui-textbox" required="true" >
            </div>
            <div class="fitem">
                <label>排序:</label>
                <input name="order" class="easyui-textbox" required="true" >
            </div>
 	</form>
</div>

<div id="dlg-buttons">
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="save()" style="width:90px">保存</a>
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
</div>

<script type="text/javascript">
        var url;
        function add(){
            $('#dlg').dialog('open').dialog('center').dialog('setTitle','新增字典');
            $('#fm').form('clear');
            url = '/dict/save';
        }
        function edit(){
            var row = $('#dataGrid').datagrid('getSelected');
            if (row){
                $('#dlg').dialog('open').dialog('center').dialog('setTitle','修改字典');
                $('#fm').form('load',row);
                url = '/dict/edit?id='+row.id;
            }
        }
        function save(){
            $('#fm').form('submit',{
                url: url,
                onSubmit: function(){
                    return $(this).form('validate');
                },
                success: function(result){
                    var result = eval('('+result+')');
                    if (result.success){
                        $('#dlg').dialog('close');        // close the dialog
                        $('#dataGrid').datagrid('reload');    // reload the  data
                    } else {
                     	$.messager.show({
                            title: 'Error',
                            msg: result.errorMsg
                        });
                    }
                }
            });
        }
        function remove(){
            var row = $('#dataGrid').datagrid('getSelected');
            if (row){
                $.messager.confirm('Confirm','确认删除字典 '+row.text,function(r){
                    if (r){
                        $.post('/dict/remove',{id:row.id},function(result){
                            if (result.success){
                                $('#dataGrid').datagrid('reload');    // reload the  data
                            } else {
                                $.messager.show({    // show error message
                                    title: 'Error',
                                    msg: result.errorMsg
                                });
                            }
                        },'json');
                    }
                });
            }
        }
    </script>
    
<script>
$("#btnSearch").click(function () {
                $('#dataGrid').datagrid('load',{
					name: $('#name').val(),
					parent_id: $('#search_parent_id').val()
				});
            });
            
$("#btnTest").click(function () {
	alert($('#comboboxTest').combobox('getValue'));
});            
</script>

<% include("../common/footer.html"){} %>